# -*- coding: utf-8 -*-
'''
Created on 29.04.2011

@author: mutius
'''
import wx
from wx._core import EVT_BUTTON
from wx._controls import EVT_TEXT
import DBEvents
from CreateBaseDialog import CreateBaseDialog
from CreateTableDialog import CreateTableDialog
from InsertIntoTableDialog import InsertIntoTableDialog
from SearchDialog import SearchDialog

class DialogCollection:
    def __init__(self, cursor):
        self.cursor = cursor
    def onCreateBase(self):
        dialog = CreateBaseDialog(None, -1)
        dialog.ShowModal()
        if len(dialog.command) != 0:
            try:
                self.cursor.execute(dialog.command)
            except:
                message = wx.MessageDialog(None, u"возникла проблема с созданием базы", u"Error", wx.ICON_ERROR)
                message.ShowModal()
                message.Destroy()
        dialog.Destroy()
        
    def onCreateTable(self):
        dialog = CreateTableDialog(None, -1, self.cursor)
        dialog.ShowModal()
        dialog.Destroy()
    
    def onInsertIntoTable(self, currentTable):
        dialog = InsertIntoTableDialog(None, -1, self.cursor, currentTable)
        dialog.ShowModal()
        if len(dialog.command) != 0:
            try:
                self.cursor.execute(dialog.command)
                print dialog.command
            except:
                message = wx.MessageDialog(None, u"возникла проблема с добавлением в таблицу", u"Error", wx.ICON_ERROR)
                message.ShowModal()
                message.Destroy()
        dialog.Destroy()
    
    def onSearch(self, currentTable, columns, grid):
        dialog = SearchDialog(None, -1, self.cursor, currentTable, columns, grid)
        dialog.ShowModal()
        #if len(dialog.command) != 0:
        #    try:
        #        self.cursor.execute(dialog.command)
        #    except:
        #        message = wx.MessageDialog(None, u"возникла проблема во время поиска", u"Error", wx.ICON_ERROR)
        #        message.ShowModal()
        #        message.Destroy()
        dialog.Destroy()
